<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib tagdir="/WEB-INF/tags/busterminal/" prefix="bt"%>
<%@taglib uri="/WEB-INF/tags/tlds/Functions.tld" prefix="f"%>

<c:set var="user" scope="session" value="${user}" />
<c:if test="${f:isActionAllowed('trip.today.list', user.getRole())}">
    <a class="btn btn-mini" href="MainServlet?action=trip.today.list" id="show-results-list" data-toggle="tab"><i class="icon-calendar icon-white"></i>&nbsp;Today trips</a>
</c:if>
<table class="table table-striped table-bordered table-condensed">
    <caption>Trip list</caption>
    <thead>
        <tr>
            <th align="center">Route</th>
            <th align="center">Trip state</th>
            <th align="center">Trip date</th>
            <th align="center">Bus</th>
            <th align="center">Driver name</th>
            <th align="center">Conductor name</th>
            <c:if test="${f:isActionAllowed('trip.edit', user.getRole())}">
                <th>&nbsp;</th>
            </c:if>
            <c:if test="${f:isActionAllowed('trip.delete', user.getRole())}">
                <th>&nbsp;</th>
            </c:if>
        </tr>
    </thead>
    <tbody>
        <c:forEach var="trip" items="${tripList}">
            <tr>
                <c:choose>
                    <c:when test="${f:isActionAllowed('route.one.list', user.getRole())}">
                        <c:url var="routeURL" value="MainServlet">
                            <c:param name="action" value="route.one.list" />
                            <c:param name="id" value="${trip.getRoute().getId()}" />
                        </c:url>
                        <td><a href="${routeURL}"><c:out value="${trip.getRoute().getRouteName()}" /></a></td>
                    </c:when>
                    <c:when test="${not f:isActionAllowed('route.one.list', user.getRole())}">
                        <td><c:out value="${trip.getRoute().getRouteName()}" /></td>
                    </c:when>
                </c:choose>
                <td><c:out value="${trip.getTripState().toString()}" /></td>
                <td><c:out value="${trip.getTripDateString()}" /></td>
                <c:choose>
                    <c:when test="${f:isActionAllowed('bus.one.list', user.getRole())}">
                        <c:url var="busURL" value="MainServlet">
                            <c:param name="action" value="bus.one.list" />
                            <c:param name="id" value="${trip.getBus().getId()}" />
                        </c:url>
                        <td><a href="${busURL}"><c:out value="${trip.getBus().getStateNumber()}" /></a></td>
                    </c:when>
                    <c:when test="${not f:isActionAllowed('bus.one.list', user.getRole())}">
                        <td><c:out value="${trip.getBus().getStateNumber()}" /></td>
                    </c:when>
                </c:choose>
                <td><c:out value="${trip.getDriverName()}" /></td>
                <td><c:out value="${trip.getConductorName()}" /></td>
                <c:if test="${f:isActionAllowed('trip.edit', user.getRole())}">
                    <c:url var="editURL" value="MainServlet">
                        <c:param name="action" value="trip.edit" />
                        <c:param name="id" value="${trip.getId()}" />
                    </c:url>
                    <td nowrap width="48"><a class="btn btn-mini" href="${editURL}" id="show-edit-form" data-toggle="tab"><i class="icon-pencil icon-white"></i>&nbsp;Edit</a></td>
                </c:if>
                <c:if test="${f:isActionAllowed('trip.delete', user.getRole())}">
                    <c:url var="deleteURL" value="MainServlet">
                        <c:param name="action" value="trip.delete" />
                        <c:param name="id" value="${trip.getId()}" />
                    </c:url>
                    <td nowrap width="62"><a class="btn btn-mini" id="show-delete-dialog" data-target="#delete-modal-window" data-toggle="modal" data-link="${deleteURL}" data-name="${trip.getRoute().getRouteName()}; ${trip.getTripState().toString()}; ${trip.getTripDateString()}; ${trip.getBus().getStateNumber()}"><i class="icon-trash icon-white"></i>&nbsp;Delete</a></td>
                </c:if>
            </tr>
        </c:forEach>
        <c:if test="${f:isActionAllowed('trip.create', user.getRole())}">
            <tr>
                <td colspan="8">
                    <a class="btn btn-mini" href="MainServlet?action=trip.create" id="show-create-form" data-toggle="tab"><i class="icon-plus icon-white"></i>&nbsp;New trip</a>
                </td>
            </tr>
        </c:if>
    </tbody>
</table>
<bt:DeleteDialog entity="trip" />
